// 放不同 action 的地方
import * as actionTypes from './constants';
import { getBannerRequset, getRecommendListRequest } from '@/api/request';

export const changeBannerListAction = (data) => ({
  type: actionTypes.CHANGE_BANNER,
  bannerList: data,
});
export const changeRecommendListAction = (data) => ({
  type: actionTypes.CHANGE_RECOMMEND_LIST,
  recommendList: data,
});
export const changeEnterLoading = (data) => ({
  type: actionTypes.CHANGE_ENTER_LOADING,
  enterLoading: data,
});
export const getBannerListAction = () => {
  return (dispatch) => {
    getBannerRequset()
      .then((data) => {
        dispatch(changeBannerListAction(data.banners));
      })
      .catch(() => {
        console.log('轮播图数据传输数据错误');
      });
  };
};
export const getRecommendListAction = () => {
  return (dispatch) => {
    getRecommendListRequest()
      .then((data) => {
        dispatch(changeRecommendListAction(data.result));
        dispatch(changeEnterLoading(false));
      })
      .catch(() => {
        console.log('推荐歌单数据传输错误');
      });
  };
};
